package cn.ronghuanet.auth.listener;

import cn.ronghuanet.auth.service.IPermissionScanService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 项目一启动就做某个事情
 * ServletContextListener 就是用来监听tomcat容器的,就是tomcat容器一启动就来做某个事情
 * 只是实现ServletContextListener,目前还只是一个普通类,还需要加注解@WebListener,还需要在启动类上加扫描
 */
@WebListener
public class InitListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;

    /**
     * 上下文初始化来运行,项目一启动就来执行
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("权限扫描开始.....................................");
        //permissionScanService.scan();
        System.out.println("权限扫描结束.....................................");
    }

    /**
     * 容器销毁时运行的
     * @param sce
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("容器销毁时执行..........................................");
    }
}
